using ELF.Consul;
using Microsoft.AspNetCore.Mvc;

namespace ELF.Modules;

[DependsOn(typeof(ElfConsulModule))]
[DependsOn(typeof(ElfdddWebApiModule))]
[DependsOn(typeof(ApplicationModule))]
[DependsOn(typeof(InfrastructureModule))]
//[DependsOn(typeof(ELFDDDDataModule))]
public class BasicApiModule : BaseModule
{
    public override async Task ConfigureServicesAsync(IHostApplicationBuilder builder)
    {

        builder.Services.AddExceptionHandler<CustomExceptionHandler>();

        // Customise default API behaviour
        builder.Services.Configure<ApiBehaviorOptions>(options =>
            options.SuppressModelStateInvalidFilter = true);

        //OpenIddict ��֤��Ϊ�������н�����֤���˴�������
        //ConfigureOpenIddict(builder.Services, builder.Configuration);
        //ConfigureAuthentication(builder.Services, builder.Configuration);

        await Task.CompletedTask;
    }

    public override async Task InitializeAsync(IApplicationBuilder app)
    {
        await Task.CompletedTask;
    }

    //private static void ConfigureAuthentication(IServiceCollection services, IConfiguration configuration)
    //{
    //    services.AddAuthorization(options =>
    //    {
    //        options.AddPolicy(PermissionConstants.PolicyNames, policy =>
    //            policy.Requirements.Add(new PermissionRequirement()));
    //    });

    //    services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
    //            .AddJwtBearer(options =>
    //            {
    //                options.TokenValidationParameters = new TokenValidationParameters
    //                {
    //                    ValidateIssuerSigningKey = true,
    //                    ValidIssuer = configuration["GatewayJwt:Issuer"],
    //                    ValidAudience = configuration["GatewayJwt:Audience"],
    //                    IssuerSigningKey = new SymmetricSecurityKey(
    //                        Encoding.UTF8.GetBytes(configuration["GatewayJwt:SecretKey"]!))
    //                };
    //            });
    //}

}
